render: Render builtin images as regular CSS images
authorBenjamin Otte <otte@redhat.com>
Mon, 19 Jan 2015 16:30:43 +0000 (17:30 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 20 Jan 2015 05:30:19 +0000 (06:30 +0100)
This not only reduces code, but also allows for builtin images to have
shadows or be transformed using -gtk-icon-transform.

gtk/gtkcssimagebuiltin.c
gtk/gtkrender.c

index f64edc385a82212be7c6a2eeb42a62785f6c9380..6562931c21d2c7bf0fde3e9cd1d38df316babea1 100644 (file)
@@ -877,6 +877,12 @@ gtk_css_image_builtin_draw (GtkCssImage            *image,
                             double                  height,
                             GtkCssImageBuiltinType  image_type)
 {
+  if (!GTK_IS_CSS_IMAGE_BUILTIN (image))
+    {
+      _gtk_css_image_draw (image, cr, width, height);
+      return;
+    }
+
   switch (image_type)
   {
   default:
index 6b03ac498525fe3fcaa6ea22cc8367012196cb22..133ba2fd2974e6b5d747d7fb43f106ed3c7afd79 100644 (file)
 
 #include "fallback-c89.c"
 
-static gboolean
-render_icon_image (GtkStyleContext *context,
-                   cairo_t         *cr,
-                   double           x,
-                   double           y,
-                   double           width,
-                   double           height)
+static void
+render_icon_image (GtkStyleContext        *context,
+                   cairo_t                *cr,
+                   double                  x,
+                   double                  y,
+                   double                  width,
+                   double                  height,
+                   GtkCssImageBuiltinType  builtin_type)
 {
   const GtkCssValue *shadows;
   cairo_matrix_t matrix, transform_matrix;
@@ -51,10 +52,7 @@ render_icon_image (GtkStyleContext *context,
 
   image = _gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE));
   if (image == NULL)
-    return TRUE;
-
-  if (GTK_IS_CSS_IMAGE_BUILTIN (image))
-    return FALSE;
+    return;
 
   shadows = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SHADOW);
 
@@ -70,20 +68,18 @@ render_icon_image (GtkStyleContext *context,
       if (_gtk_css_shadows_value_is_none (shadows))
         {
           cairo_transform (cr, &matrix);
-          _gtk_css_image_draw (image, cr, width, height);
+          gtk_css_image_builtin_draw (image, cr, width, height, builtin_type);
         }
       else
         {
           cairo_push_group (cr);
           cairo_transform (cr, &matrix);
-          _gtk_css_image_draw (image, cr, width, height);
+          gtk_css_image_builtin_draw (image, cr, width, height, builtin_type);
           cairo_pop_group_to_source (cr);
           _gtk_css_shadows_value_paint_icon (shadows, cr);
           cairo_paint (cr);
         }
     }
-
-  return TRUE;
 }
 
 static void
@@ -105,15 +101,7 @@ gtk_do_render_check (GtkStyleContext *context,
   else
     image_type = GTK_CSS_IMAGE_BUILTIN_CHECK;
 
-  if (render_icon_image (context, cr, x, y, width, height))
-    return;
-
-  cairo_translate (cr, x, y);
-
-  gtk_css_image_builtin_draw (_gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE)),
-                              cr,
-                              width, height,
-                              image_type);
+  render_icon_image (context, cr, x, y, width, height, image_type);
 }
 
 /**
@@ -178,15 +166,7 @@ gtk_do_render_option (GtkStyleContext *context,
   else
     image_type = GTK_CSS_IMAGE_BUILTIN_OPTION;
 
-  if (render_icon_image (context, cr, x, y, width, height))
-    return;
-
-  cairo_translate (cr, x, y);
-
-  gtk_css_image_builtin_draw (_gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE)),
-                              cr,
-                              width, height,
-                              image_type);
+  render_icon_image (context, cr, x, y, width, height, image_type);
 }
 
 /**
@@ -263,15 +243,7 @@ gtk_do_render_arrow (GtkStyleContext *context,
     break;
   }
 
-  if (render_icon_image (context, cr, x, y, size, size))
-    return;
-
-  cairo_translate (cr, x, y);
-
-  gtk_css_image_builtin_draw (_gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE)),
-                              cr,
-                              size, size,
-                              image_type);
+  render_icon_image (context, cr, x, y, size, size, image_type);
 }
 
 /**
@@ -439,15 +411,7 @@ gtk_do_render_expander (GtkStyleContext *context,
                      : GTK_CSS_IMAGE_BUILTIN_EXPANDER_VERTICAL_LEFT;
     }
 
-  if (render_icon_image (context, cr, x, y, width, height))
-    return;
-
-  cairo_translate (cr, x, y);
-
-  gtk_css_image_builtin_draw (_gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE)),
-                              cr,
-                              width, height,
-                              image_type);
+  render_icon_image (context, cr, x, y, width, height, image_type);
 }
 
 /**
@@ -1001,11 +965,6 @@ gtk_do_render_handle (GtkStyleContext *context,
   gtk_render_background (context, cr, x, y, width, height);
   gtk_render_frame (context, cr, x, y, width, height);
 
-  if (render_icon_image (context, cr, x, y, width, height))
-    return;
-
-  cairo_translate (cr, x, y);
-
   if (gtk_style_context_has_class (context, GTK_STYLE_CLASS_GRIP))
     {
       GtkJunctionSides sides = gtk_style_context_get_junction_sides (context);
@@ -1039,10 +998,7 @@ gtk_do_render_handle (GtkStyleContext *context,
       type = GTK_CSS_IMAGE_BUILTIN_HANDLE;
     }
 
-  gtk_css_image_builtin_draw (_gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE)),
-                              cr,
-                              width, height,
-                              type);
+  render_icon_image (context, cr, x, y, width, height, type);
 }
 
 /**
@@ -1136,25 +1092,6 @@ gtk_render_paint_spinner (cairo_t *cr,
   cairo_restore (cr);
 }
 
-static void
-gtk_do_render_activity (GtkStyleContext *context,
-                        cairo_t         *cr,
-                        gdouble          x,
-                        gdouble          y,
-                        gdouble          width,
-                        gdouble          height)
-{
-  if (render_icon_image (context, cr, x, y, width, height))
-    return;
-
-  cairo_translate (cr, x, y);
-
-  gtk_css_image_builtin_draw (_gtk_css_image_value_get_image (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_ICON_SOURCE)),
-                              cr,
-                              width, height,
-                              GTK_CSS_IMAGE_BUILTIN_SPINNER);
-}
-
 /**
  * gtk_render_activity:
  * @context: a #GtkStyleContext
@@ -1187,7 +1124,7 @@ gtk_render_activity (GtkStyleContext *context,
   cairo_save (cr);
   cairo_new_path (cr);
 
-  gtk_do_render_activity (context, cr, x, y, width, height);
+  render_icon_image (context, cr, x, y, width, height, GTK_CSS_IMAGE_BUILTIN_SPINNER);
 
   cairo_restore (cr);
 }